package de.fhaugsburg.games.boardgames;

import java.util.ArrayList;
import java.util.List;

public class CircularList<T> {

	private List<T> list;
	private int current;

	public CircularList() {
		list = new ArrayList<T>();
	}

	public void add(T t) {
		list.add(t);
	}

	public T next() {
		if (current < list.size() - 1)
			return list.get(++current);
		else {
			current = 0;
			return list.get(current);
		}
	}

	public void reset() {
		current = 0;
	}

	public T prev() {
		if (current > 0)
			return list.get(--current);
		else {
			current = list.size() - 1;
			return list.get(current);
		}
	}

	public List<T> getAll() {
		return list;
	}

}
